#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <tlhelp32.h>

void _tmain( int argc, TCHAR *argv[] )
{
	
	HANDLE  hndl;
	DWORD dwExitCode = 0;
	PROCESSENTRY32  procEntry={0};
	DWORD dwsma = GetLastError();
	
	char pid[4];
	//printf("%s\n",argv[1]);
	if( argc != 2)
    {
        printf("Usage: %s [pid]\n\t -e", argv[0]);
        return;
    }
	hndl=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
	
	
	procEntry.dwSize = sizeof( PROCESSENTRY32 );
	Process32First(hndl,&procEntry);
	do
	{
		//printf("%d,%d,%d\n",procEntry.th32ProcessID,procEntry.th32ProcessID==(int)argv[1],argv[0]);
		sprintf(pid,"%d",procEntry.th32ProcessID);
		//printf("%s,%s,%d\n",pid,argv[1],strcmp(pid,argv[1])==0);
		if(strcmp(pid,argv[1])==0)
		{
			GetExitCodeProcess(hndl,&dwExitCode);
			hndl=OpenProcess(1,0,procEntry.th32ProcessID);
			if(0==TerminateProcess(hndl,dwExitCode))
			{
				printf("%d:%s\n",GetLastError(),"Process Security and Access Rights");
			}
			//printf("%d",CloseHandle(hndl));
			break;
		}
	}
	while(Process32Next(hndl,&procEntry));    
	
}